package com.example.saiaadmin.common;

import com.example.saiaadmin.entry.EbSystemUser;
import com.example.saiaadmin.po.CusterUserDetails;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

public class GetCunrrentUser {
    /**
     * 获取当前用户
     * @return
     */
    public  EbSystemUser getUser(){
        UsernamePasswordAuthenticationToken authenticationToken = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
        CusterUserDetails user = (CusterUserDetails) authenticationToken.getPrincipal();
        EbSystemUser systemUser = user.getUser();
        return systemUser;
    }


}
